package com.siqi.hr.system.common.sql;


import com.siqi.hr.system.common.chan.BeSql;

/**
 * 添加引用字段关系表对象
 * @author xiaogq
 */
public class RelatedTable implements BeSql {
    public static final String RELATED_HEAD = "z_";
    /**
     * 两个实体关系表名（z_x_y）
     */
    private String tableName;

    /**
     * 主表名
     */
    private STable hostTable;

    /**
     * 辅表名
     */
    private STable relatedTable;

    public StringBuilder toSqlString() {
        return new StringBuilder(this.tableName + " as " + this.tableName);
    }

    public String getTableName() {
        return this.tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public RelatedTable(String tableName) {
        this.tableName = tableName;
        String[] t = tableName.split("_");
        this.hostTable = new STable("t_" + t[1]);
        this.relatedTable = new STable("t_" + t[2]);
    }

    public STable getHostTable() {
        return this.hostTable;
    }

    public STable getRelatedTable() {
        return this.relatedTable;
    }
}
